from django.db import models
from user.models import User


class Post(models.Model):
    class Meta:
        db_table = 'post'

    id = models.AutoField(primary_key=True)
    title = models.CharField(max_length=256, null=False)
    pubdata = models.DateTimeField(auto_now=True)
    author = models.ForeignKey(User, on_delete=False)  # 定义外键

    def __repr__(self):
        return "<Post  id:{}  title:{}>".format(self.id, self.title)

    __str_ = __repr__


class Content(models.Model):
    class Meta:
        db_table = 'content'

    post = models.OneToOneField(Post, to_field='id', on_delete=False)
    content = models.TextField(null=False)

    def __repr__(self):
        return "<Content  {}  {}>".format(self.id, self.post)

    __str__ = __repr__
